package relation

import (
	"dy/pkg/code"
	"dy/pkg/jwt"
	"github.com/gin-gonic/gin"
)

func (u *ControllerRelation) RelationAction(ctx *gin.Context) {
	type param struct {
		Token      string `form:"token" json:"token" binding:"required"`
		ToUserId   int    `form:"to_user_id" json:"to_user_id" binding:"required"`
		ActionType int    `form:"action_type" json:"action_type" binding:"required"`
	}
	var request param
	err := ctx.Bind(&request)
	if err != nil {
		code.ErrReturn(ctx, err.Error())
		return
	}

	userId, err := jwt.ParseToken(request.Token)
	if err != nil {
		code.ErrReturn(ctx, err.Error())
		return
	}

	search := map[string]interface{}{}
	search["user_id"] = userId
	search["follow_id"] = request.ToUserId
	search["action_type"] = request.ActionType

	err = u.srv.Relation().Action(ctx, search)
	if err != nil {
		code.ErrReturn(ctx, err.Error())
		return
	}

	ctx.JSON(200, gin.H{
		"status_code": 0,
		"status_msg":  "success",
	})
	return
}
